package com.bakend.common;


import lombok.Data;

@Data
public class R {
    private int code;
    private String msg;
    private Object data;

    //==================构造函数======================

    public R() {
    }

    public R(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public R(int code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    //==================固定结果======================

    public static R Ok(){
        return new R().setCode(200);
    }
    public static R Ok(int code){
        return new R().setCode(code);
    }
    public static R Ok(int code,String msg){
        return new R(code,msg);
    }

    public static R Error(){
        return new R().setCode(400);
    }
    public static R Error(int code){
        return new R().setCode(code);
    }
    public static R Error(int code,String msg){
        return new R(code,msg);
    }

    //认证错误
    public static R AuthenticationError(){
        return new R().setCode(700).setMsg("认证失败");
    }

    //==================set方法======================

    public R setCode(int code){
        this.code = code;
        return this;
    }
    public R setMsg(String msg){
        this.msg = msg;
        return this;
    }
    public R setData(Object data){
        this.data = data;
        return this;
    }
}
